<template>
    <el-container>
        <!-- 头部区域 -->
        <el-header>
            <div class="headers">
                <span class="toggle-button" @click="toggleCollapse">
                    <i :class="isCollapse ? 'el-icon-s-fold' : 'el-icon-s-unfold'"></i>
                </span>
                <span>电商后台管理系统</span>
            </div>
            <!-- <el-button type="info" @click="logout" class="el-dropdown-link">退出</el-button> -->
            <el-dropdown>
                <span class="el-dropdown-link">
                    用户
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>个人信息</el-dropdown-item>
                    <el-dropdown-item><span @click="logout">退出登录</span></el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-header>
        <!-- 页面主体区域 -->
        <el-container>
            <!-- 侧边栏区域 -->
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <!-- 侧边栏菜单区域 -->
                <el-menu background-color="rgb(53, 0, 97)" text-color="#fff" active-text-color="rgb(140,0,255,0.8)" unique-opened :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
                    <!-- 一级菜单 -->
                    <el-submenu index="1">
                        <!-- 一级菜单的模板区域 -->
                        <template slot="title">
                            <!-- 图标 -->
                            <i class="el-icon-user-solid"></i>
                            <!-- 文本 -->
                            <span>用户管理</span>
                        </template>

                        <!-- 二级菜单 -->
                        <el-menu-item index="users">
                            <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-menu"></i>
                                <!-- 文本 -->
                                <span>用户列表</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                    <el-submenu index="2">
                        <!-- 一级菜单的模板区域 -->
                        <template slot="title">
                            <!-- 图标 -->
                            <i class="el-icon-s-goods"></i>
                            <!-- 文本 -->
                            <span>商品管理</span>
                        </template>

                        <!-- 二级菜单 -->
                        <el-menu-item index="list">
                            <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-s-operation"></i>
                                <!-- 文本 -->
                                <span>商品列表</span>
                            </template>
                        </el-menu-item>
                        
                        <!-- 二级菜单 -->
                        <el-menu-item index="cate">
                            <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-menu"></i>
                                <!-- 文本 -->
                                <span>商品分类</span>
                            </template>
                        </el-menu-item>

                        <!-- 二级菜单 -->
                        <el-menu-item index="add">
                            <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-edit-outline"></i>
                                <!-- 文本 -->
                                <span>添加商品</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 右侧内容主体区域 -->
            <el-main>
                <!-- 路由占位符 -->
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data() {
        return {
            // 是否折叠侧边导航栏
            isCollapse: false,
            activePath: ''
        }
    },
    created() {
        // this.getMenuList()
        this.activePath = window.sessionStorage.getItem('activePath')
    },
    methods: {
        // 清空token返回登录页
        logout() {
            window.sessionStorage.clear()
            this.$router.push('/')
        },
        // 切换菜单的折叠与展开
        toggleCollapse() {
            this.isCollapse = ! this.isCollapse
        },
        // 选取高亮
        saveNavState (activePath) {
            window.sessionStorage.setItem('activePath', activePath)
            this.activePath = activePath
        }
    },
    // // 获取所有的菜单
    // async getMenuList() {
    //     const {data: res} = await this.$http.get('menus')
    //     console.log(res)
    // }
}
</script>

<style lang="less" scoped>
.el-container {
    height: 100%;
}
.el-header {
    background-color: rgb(39, 0, 83);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.headers {
    color: white;
    // 60, 0, 109
}
.toggle-button {
    margin-right: 25px;
    cursor: pointer;
}
.el-dropdown-link {
    cursor: pointer;
    color: white;
}
.el-aside {
    background-color: rgb(44, 0, 80);
    border-right: none;
}
.el-main{
    background-color: white;
}
</style>